$(function(){
	//全局搜索
	$(function(e) {
   var $area = $('.search-area'),
        $showhide = $('.showhide-search'),
        $input = $('.search-input');      
    $('.course-nav-hd').on('click', '.showhide-search', function (event){
        var isShow = $(this).attr('data-show');
        if( isShow == 'no'){
            show()
            $input.focus();
            $input.keyup(function(){
            	$(".search-result").css("display","block");
            });
            $(".search-input").css("border","1px solid #bcbcbc");
        }else{
        	if($input.val()==""){
        		hide()
        	}
        }                    
        return false;
    })        
    $('.course-nav-hd').on('click', '.search-area', function (event){
        return false;
    })         
    $(document).on('click', function (){
        if( $input.val() != ''){
            hide()
        }else{
        	hide()
        }
    })       
    var show = function (){
        $showhide.attr('data-show', 'yes')
        $area.show(1, function (){ $area.removeClass('min') })
    }     
    var hide = function (){
        $showhide.attr('data-show', 'no')
        $area.fadeOut('slow', function (){
            $area.addClass('min')
        })
    }
	})
	
	//已关注
	var $follow=1;
	$(".follow").on('click',function(){
		if($follow==1){
			$(this).html("已关注").css({"background":"#ececec"});
			$(this).css("color","#666");
			$follow++;
		}else if($follow!=1){		
			$(this).html("+ 关注").css({"background":"#49b4e1"});
			$(this).css("color","#fff");
			$follow=1;
		}
	})
	
	//发表评论 
	$(".textarea").on({
		'focus':function(){
			if($(".pl-limit").html()>300){
				$(".pl-input-warp").css("border","1px solid red");
			}
			else{
				$(".pl-input-warp").addClass("pl-input-warps");
				$(".pl-input-warp").css("border","1px solid green");
			}
			
		},
		'keyup':function(){		
			//$(".pl-input-warp").css("border","1px solid #d3dce0");
			var num=300-$(".textarea").val().length;
			if(num>=0){
				$(".pl-limit").html(num);
				//$(".pl-input-warp").css("border","1px solid #d3dce0");
			}else{
				$(".pl-limit").html(Math.abs(num)+300);
				$(".pl-input-warp").css("border","1px solid red");
				return false;
			}
			
			if($(".pl-limit").html()<300){  		  	
				$(".pl-input-warp").css("border","1px solid #d3dce0");
			}
	},
	'blur':function(){
		if($(".pl-limit").html()>300){  		  	
			$(".pl-input-warp").css("border","1px solid red");
		}else{
		  	$(".pl-input-warp").css("border","1px solid #d3dce0");
		  	$(".pl-input-warp").removeClass("pl-input-warps");
		}
	}
});
   		    
$(".input-btn-pl").click(function(){
	var $val=$(".textarea").val();
	var $val_length=$(".textarea").val().length;
	if($val == ""){
		$(".pl-input-warp").css("border","1px solid red");
		return false;
	}else if($val_length>300){
		return false;
	}else{
		alert("这里写成功后的东西");
	}
})

	//免费视频的选项卡切换
	$(".price-left-tab ul li").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
		var _index=$(".price-left-tab ul li").index(this);
		$(".price-left-bd").eq(_index).show().siblings().hide();
	})
	
	//点击立即播放跳转
	$(".sign").on("click",function(){
		window.location.href="video.html"
	})
})
